package com.rmt.www.daoImpl;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;

import com.rmt.www.constant.ArtifactStatus;
import com.rmt.www.dao.ImplementationArtifactHistoryDao;
import com.rmt.www.vo.History;
import com.rmt.www.vo.ImplementationArtifact;
import com.rmt.www.vo.ImplementationArtifactHistory;

public class ImplementationArtifactHistoryDaoImpl implements
		ImplementationArtifactHistoryDao {
		
		private JdbcTemplate jdbcTemplate;
	
		public void setDataSource(DataSource dataSource) {
			this.jdbcTemplate = new JdbcTemplate(dataSource);
			}

		public void insertImplementationArtifactHistory(ImplementationArtifactHistory history) {
			jdbcTemplate.update("insert into implartifacthistory(pid,title,function,input,output,processingsteps,algorithm,errorhandling,code,priority,effort,cost,risk,comment,createrid,createdtime,updaterid,updatedtime,updatedtimes,version,status,language,implartifactid) " +
				"values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", 
				new Object[]{
					history.getPid(),
					history.getTitle(),
					history.getFunction(),
					history.getInput(),
					history.getOutput(),
					history.getProcessingsteps(),
					history.getAlgorithm(),
					history.getErrorhandling(),
					history.getCode(),
					history.getPriority(),
					history.getEffort(),
					history.getCost(),
					history.getRisk(),
					history.getComment(),
					history.getCreaterid(),
					history.getCreatedtime(),
					history.getUpdaterid(),
					history.getUpdatedtime(),
					history.getUpdatedtimes(),
					history.getVersion(),
					history.getStatus(),
					history.getLanguage(),
					history.getImplartifactid()
				},new int[] {
					java.sql.Types.INTEGER,
					java.sql.Types.VARCHAR,
					java.sql.Types.VARCHAR,
					java.sql.Types.VARCHAR,
					java.sql.Types.VARCHAR,
					java.sql.Types.VARCHAR,
					java.sql.Types.VARCHAR,
					java.sql.Types.VARCHAR,
					java.sql.Types.VARCHAR,
					java.sql.Types.VARCHAR,
					java.sql.Types.INTEGER,
					java.sql.Types.VARCHAR,
					java.sql.Types.VARCHAR,
					java.sql.Types.VARCHAR,
					java.sql.Types.INTEGER,
					java.sql.Types.TIMESTAMP,
					java.sql.Types.INTEGER,
					java.sql.Types.TIMESTAMP,
					java.sql.Types.INTEGER,
					java.sql.Types.VARCHAR,
					java.sql.Types.VARCHAR,
					java.sql.Types.VARCHAR,
					java.sql.Types.INTEGER
				});
		}
		
		
		@SuppressWarnings("unchecked")
		public List<ImplementationArtifactHistory> getImplementationArtifactHistoryById(int id) {
			return (List<ImplementationArtifactHistory>)(this.jdbcTemplate.query("select * from implartifacthistory where implartifactid=?",
					new Object[]{id}, 
					new int[]{java.sql.Types.INTEGER}, 
					new ImplementationArtifactHistoryRowMapper()));
		}
		

		
}
